package com.qf.service.impl;

import com.qf.mapper.BranchMapper;
import com.qf.mapper.ProjectMapper;
import com.qf.mapper.SubitemMapper;
import com.qf.model.Branch;
import com.qf.model.Subitem;
import com.qf.page.PageResult;
import com.qf.page.QueryPageBean;
import com.qf.service.BranchService;
import com.qf.service.SubitemService;
import com.qf.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class SubitemServiceImpl implements SubitemService {
    @Autowired
    private SubitemMapper subitemMapper;
    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public List<Subitem> getAll() {
        List<Subitem> all = subitemMapper.findAll();
        return all;
    }

    //分页查询+模糊查询
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer CurrentPage = queryPageBean.getCurrentPage();
        Integer PageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageResult pageResult = new PageResult();
        //当前页结果
        List<Subitem> rows = subitemMapper.findPage((CurrentPage-1)*PageSize, PageSize,queryString);
        //总记录数
        Long count = subitemMapper.count(queryString);
        pageResult.setTotal(count);
        pageResult.setRows(rows);
        return pageResult;
    }

    //新建开发商并绑定工程
    @Override
    @Transactional
    public int add(Subitem subitem) {
        subitem.setUpdatetime(new Date());
        subitem.setSuid(UUIDUtils.uuid());
        //新增stage
        int i = subitemMapper.addOne(subitem);
        return i;
    }


    //根据sid查询stage回显
    @Override
    public Subitem findById(String suid) {
        Subitem subitem = subitemMapper.findById(suid);

        return subitem;
    }

    //修改branch
    @Override
    @Transactional
    public int edit(Subitem subitem) {
        subitem.setUpdatetime(new Date());
        //修改developer
        int i = subitemMapper.editOne(subitem);
        return i;
    }

    //删除branch
    @Override
    @Transactional
    public int delete(String suid) {
        int i = subitemMapper.delete(suid);
        return i;
    }
}
